package com.nameli.admin.service.impl.system;

import cn.hutool.core.bean.BeanUtil;
import com.nameli.SIM.bean.entity.sys.SysPermission;
import com.nameli.SIM.bean.entity.sys.SysRole;
import com.nameli.SIM.bean.vo.LoginVo;
import com.nameli.SIM.mapper.SysUserMapper;
import com.nameli.SIM.bean.entity.sys.SysUser;
import com.nameli.admin.service.SysUserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author NAME-L
 * @Description TODO
 * @className SysUserServiceImpl
 * @date 2021-12-27 16:09:19
 */
@Component
public class SysUserServiceImpl implements SysUserService {
    private static final Log logger = LogFactory.getLog(SysUserServiceImpl.class);

    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public SysUser selectByUserName(String userName) {
        return sysUserMapper.selectByUserName(userName);
    }

    @Override
    public SysUser selectByUserId(Long userId) {
        return sysUserMapper.selectByUserId(userId);
    }

    @Override
    public List<SysRole> getAllRolesByName(String username) {
        logger.info("SysUserServiceImpl - selectByUserName");
        return sysUserMapper.getAllRolesByName(username);
    }

    @Override
    public List<SysPermission> getAllPermissionsByName(String userName) {
        return sysUserMapper.getAllPermissionsByName(userName);
    }

    @Override
    public SysUser login(String userName, String password) {
        return sysUserMapper.login(userName , password);
    }

    @Override
    public LoginVo beanTransform(SysUser sysUser) {
        return BeanUtil.toBean(sysUser, LoginVo.class);
    }
}
